package dvonn.game;

public class Place2D {

	private Token token;
	private byte size;
	private boolean dvonn;
	private boolean movable;
	private int x;
	private int y;
	
	public Place2D(Token t, int x2, int y2) {
		this.token = t;
		this.x = x2;
		this.y = y2;
		this.size = 1;
		if (t==Token.DVONN) this.dvonn = true;
		else this.dvonn = false;
		this.movable = false;
	}
	
	public Place2D(Token t, int x, int y, byte size, boolean dvonn, boolean movable) {
		this.token = t;
		this.x = x;
		this.y = y;
		this.size = size;
		this.dvonn = dvonn;
		this.movable = movable;
	}
	
	public void add(Place2D p) {
		this.token = p.token;
		this.size += p.size;
		this.dvonn |= p.dvonn; 
	}
	
	public void makeMovable() { this.movable = true; }
	
	public Token getToken() { return this.token; }
	
	public int getX() { return this.x; }
	
	public int getY() { return this.y; }
	
	public int getSize() { return this.size; }
	
	public boolean isMovable() { return this.movable; }
	
	public boolean withDvonn() { return this.dvonn; }
	
	public boolean equals(Object o) {
		if (!(o instanceof Place2D)) return false;
		Place2D p = (Place2D) o;
		if (p.token!=this.token) return false;
		if (p.x!=this.x) return false;
		if (p.y!=this.y) return false;
		if (p.size!=this.size) return false;
		if (p.dvonn!=this.dvonn) return false;
		if (p.movable!=this.movable) return false;
		return true;
	}
	
	public int hashCode() {
		return this.x * 256 + this.y;
	}
	
	public Place2D clone() {
		return new Place2D(this.token, this.x, this.y, this.size, this.dvonn, this.movable);
	}
	
	public String toString() {
		String output = new String();
		output = "<"+this.token+this.size;
		if (this.dvonn) output = output+"+";
			else output = output+"-";
		if (this.movable) output = output+"m";
		else output = output+" ";
		return output+">";
	}
}
